<?php
require_once('modules/config.class.php');

/**
 * Internationalization management
 * @author delormef
 *
 */
class I18n{
	static private $_instance=null;
	private $language=null;
	private $messages=array();
	
	public function __construct(){
		$config = Config::getInstance();
		if($config->get('i18n','default')){
			$this->setLanguage($config->get('i18n','default'));
		}else{
			$this->setLanguage("en-EN");
		}
	}
	
	public function setLanguage($lang){
		if($lang!=""){
			if(file_exists("i18n/application_".$lang.".properties")){
				$this->messages=parse_ini_file("i18n/application_".$lang.".properties");
			}
		}
	}
	public function get($key){
		if(isset($this->messages[$key])){
			return $this->messages[$key];
		}else{
			return "{{key $key not declared in the ".$this->language."}}";
		}
	}
	/**
	 * return the static instance of the THeme Manager.
	 * create the instance if does not already exist.
	 */
	public function getInstance(){
		if(!isset(self::$_instance)){
			self::$_instance = new I18n();
		}
		return self::$_instance;
	}
}
function __($key){
	return I18n::getInstance()->get($key);
}
?>